/**
 * 添加或者修改页面
 */
var StockStrategyInfoDlg = {
    data: {
        code: "",
        name: "",
        buyPrice: "",
        stopLossPrice: "",
        takeProfitPrice: "",
        buyDate: "",
        profitRate: "",
        sellDate: "",
        buyAmount: "",
        sellAmount: "",
        status: "",
        eventType: "",
        gmtCreate: "",
        gmtModified: ""
    }
};

layui.use(['form', 'admin', 'ax', 'laydate'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;

    //让当前iframe弹层高度适应
    admin.iframeAuto();
    $("#code").bind('input', function () {
        var a = $("#code").val();
        if (a.length == 6) {
            const sina_stock_url = Feng.ctxPath + '/stock/stockStrategy/sina?code=';

            if (a.indexOf('60') == 0) {
                a = 'sh' + a
            } else {
                a = 'sz' + a
            }
            var ajax = new $ax(sina_stock_url + a);
            var result = ajax.start();
            $("#name").val(result.data)
        }


    });

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/stock/stockStrategy/addItem", function (data) {
            Feng.success("添加成功！");
            window.location.href = Feng.ctxPath + '/stock/stockStrategy'
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/stock/stockStrategy'
    });
    layui.form.on('radio', function (data) {
        console.log(data.elem.name)
        if (data.value != 'define'&&data.elem.name=='selectPosition') {
            $("#stockPosition").val(data.value)
        }else  if(data.value=='define'&&data.elem.name=='selectPosition'){
            $("#stockPosition").val('')
        }
    })

    $("#showMore").click(function () {
        isShow = $("#showOrHide").css('display')
        if (isShow == 'none' || isShow != 'block') {
            $("#showOrHide").show()
            $("#showContent").html('<i class=\"layui-icon\" id=\"showContent\"> 收缩>></i>')

        } else {
            $("#showOrHide").hide()
            $("#showContent").html('<i class=\"layui-icon\" id=\"showContent\"> 展开>></i>')
        }
    });

    $("#showOrHide").hide()

    //渲染时间选择框
    laydate.render({
        elem: '#sellDate'
    });
    laydate.render({
        elem: '#buyDate'
    });

});